
import { _decorator, Component, Node, Vec2, View, view, Canvas, UITransform } from 'cc';
import { Main } from '../Main';
import { MouseInput } from '../Player/MouseInput';
const { ccclass, property } = _decorator;


 
@ccclass('JoyStick')
export class JoyStick extends Component {
	
	@property({type:Node})
	private bg:Node=null
	@property({type:Node})
	private circle:Node=null
	@property({type:MouseInput})
	private mouseInput:MouseInput=null
    
	private maxLength=95

	loop(){
		let dir=this.mouseInput.getDir()
		if(!dir){
			this.bg.active=false
			return
		}
		this.bg.active=true
	
		this.bg.setPosition(this.mouseInput.startPos.x-Main.I.screenWidth/2,this.mouseInput.startPos.y-Main.I.screenHeight/2)
		var length=Vec2.distance(this.mouseInput.mousePos,this.mouseInput.startPos)
		length=Math.min(length,this.maxLength)
		let circlePos=new Vec2()
		Vec2.multiplyScalar(circlePos,dir,length)
		this.circle.setPosition(circlePos.x,circlePos.y)

		Main.I.testMessage.string=`mouseInput.x:${this.mouseInput.startPos.x}  mouseInput.y:${this.mouseInput.startPos.y}
length:${length}
circlePos:${circlePos}`
	}

  
}


